﻿// census.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

#include <iostream>
#include <ctime>
#include <string>

#include "census.h"

using namespace std;
using namespace cv;


int _tmain(int argc, _TCHAR* argv[])
{
	Mat img = imread("tsukuba_l.bmp", CV_LOAD_IMAGE_GRAYSCALE);
	
	cv::Mat oringin = img;

	int type[3] = {
		CV_8UC1, CV_16UC1, CV_32FC1
	};
	string method[3] = {
		"8bit", "16bit", "32bit"
	};
	Mat dst, dst2;
	Census census;
	for (int j = 0; j < 3; ++j)
	{
		oringin.convertTo(img, type[j]);

		clock_t start = clock();
		for (int i = 0; i < 100; ++i)
		{
			census.serial(img, dst);
		}
		int time = clock() - start;
		cout << "time for serial implementation is :" << time
			<< " ms at " << method[j] << " image" << endl;
		start = clock();
		for (int i = 0; i < 100; ++i)
		{
			census(img, dst2);
		}
		int time2 = clock() - start;
		int acc = ((double)time / time2 + 0.5);
		cout << "time for SIMD implementation is :" << time2
			<< " ms at " << method[j] << " image with " << acc << "x" << endl;
	}
	

	vector<Mat> spilts_mat(8), spilts_mat2(8);
	cv::Mat error = dst - dst2;

	cv::split(error, spilts_mat2);
// 	cv::split(dst2, spilts_mat2);
	imshow("image", oringin);
	imshow("error0", spilts_mat2[0]);
	imshow("error1", spilts_mat2[1]);
	imshow("error2", spilts_mat2[2]);
	imshow("error3", spilts_mat2[3]);

	waitKey();

	return 0;
}

